<?php
namespace My\Model;

use Utuo\UtuoModel;

class ProductPayApiModel extends UtuoModel {
	
	protected  $_auto = array(
		array('cfg', 'getCfg', self::MODEL_BOTH, 'callback'),
	); 
	
	public $status = array(
		'0' => "启用",
		'1' => "禁用"
	);
	
	/**
	 * 配置所有接口的配置参数
	 * @var unknown
	 */
	public $payMethod = array(
			'Tenpay' => array(
			   'name' => '财付通', 
			   'fields' => array(
				 array('name' => 'key', 'title' => '支付密钥', 'isRequired' => 1),
				 array('name' => 'partner', 'title' => '合作商ID', 'isRequired' => 1),
			   )
			),
			'Alipay' => array(
			   'name' => '支付宝', 
			   'fields' => array(
			   	 array('name' => 'email', 'title' => '邮箱', 'isRequired' => 1),
				 array('name' => 'key', 'title' => '支付密钥', 'isRequired' => 1),
				 array('name' => 'partner', 'title' => '合作商ID', 'isRequired' => 1),
			   )
			),
			'WxTenpay' => array( /* 支付时本配置信息将自动加入 appid 与 appsecret的配置 */
				'name' => '微信支付',
				'version' => 'v3.3.6',
				'fields' => array(
					array('name' => 'Mchid', 'title' => '商户 ID', 'isRequired' => 1, "description" => "身份标识,在微信发送的邮件中查看。"),
					array('name' => 'Key', 'title' => '商户支付密钥 Key', 'isRequired' => 1),
					array('name' => 'SSLCertPath', 'title' => 'Cert证书', 'isRequired' => 0, 'type' => 'file', 'filter' => "*.pem"),
					array('name' => 'SSLKeyPath', 'title' => '私钥证书', 'isRequired' => 0, 'type' => 'file', 'filter' => "*.pem"),
				    array('name' => 'SSLRootCaPath', 'title' => '根证书', 'isRequired' => 0, 'type' => 'file', 'filter' => "*.pem"),
					array('name' => 'Debug', 'title' => '调试', 'isRequired' => 1, 'type' => 'select', 'data' => array('' => '==请选择==', '1' => '是', '0' => '否')),
				)
			),
	);
	
	public function getCfg() {
		if(!isset($_REQUEST['tag'])) return false;
		$cfg = array();
		$tag = I("tag");
		if($payCfg = $this->payMethod[$tag]) {
			foreach ($payCfg['fields'] as $v) {
				$cfg[$v['name']] = $_POST[$v['name']];
			}
		}
		return serialize($cfg);
	}
	
}